<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>D站</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link rel="icon" th:href="@{/pagesResource/img/icon.png}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/animate.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/bootstrap.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/iconfont.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/flatpickr.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/style.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/responsive.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/pagesResource/css/color.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/rechargeCoinRes/css/amazeui.min.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/rechargeCoinRes/css/main.css}" />
</head>
<body>
<div class="wrapper">
    <div th:include="main/simpleHeader :: header"></div>
</div>
<div class="pay">
    <!--主内容开始编辑-->
    <div class="tr_recharge">
        <div class="tr_rechtext">
            <p class="te_retit"><img th:src="@{/rechargeCoinRes/images/coin.png}" alt="" />可观看次数充值中心</p>
            <p>为您推出以下几种购买套餐，充值获取可观看次数，可以解锁付费视频。</p>
            <p>每次解锁一次付费视频花费一次可观看机会。</p>
        </div>
        <form action="/aliPay/payPage" method="post" class="am-form" id="doc-vld-msg">
            <div class="tr_rechbox">
                <div class="tr_rechhead">
                    <img th:src="@{/images/userIcon/{userIc}(userIc=${session.userInfo.userIcon})}" />
                    <p>充值账户：
                        <span th:utext="${session.userInfo.userName}">王凯</span>
                        <span th:utext="'('+${session.userInfo.userPhone}+')'">xxxxxxxxxx</span>
                    </p>
                    <div class="tr_rechheadcion">
                        <img th:src="@{/rechargeCoinRes/images/coin.png}" alt="" />
                        <span>剩余观看次数：<span th:text="${session.userInfo.privilegetimes} + 次">0次</span></span>
                    </div>
                </div>
                <div class="tr_rechli am-form-group">
                    <ul class="ui-choose am-form-group" id="uc_01">
                        <li th:each="subPackage:${subPackList}">
                            <label class="am-radio-inline">
                                <input type="radio"  th:value="${subPackage.subPackPrice.toString()}"
                                       name="docVlGender" required data-validation-message="请选择一项充值套餐"
                                th:text="${subPackage.subPackDescription}+次">
                            </label>
                        </li>

                    </ul>
                </div>
                <div class="tr_rechcho am-form-group">
                    <span>充值方式：</span>
                    <label class="am-radio pay_check">
                        <input type="radio" name="payMethod" value="" data-am-ucheck data-validation-message="请选择一种充值方式" required><img th:src="@{/rechargeCoinRes/images/zfbpay.png}" />
                    </label>
                </div>
                <div class="tr_rechnum">
                    <span>应付金额：</span>
                    <p class="rechnum">¥ 0.00</p>
                </div>
                <div class="btn-sbmit recharge_btn">
                    <button type="submit" class="btn btn-default" id="submitVideoInfo">充值</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" th:src="@{/pagesResource/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/pagesResource/js/jquery.validate.min.js}"></script>
<script type="text/javascript" th:src="@{/pagesResource/js/messages_zh.min.js}"></script>
<script th:src="@{/pagesResource/js/bootstrap.min.js}"></script>
<script th:src="@{/pagesResource/js/script.js}"></script>
<script type="text/javascript" th:src="@{/rechargeCoinRes/js/amazeui.min.js}"></script>
<script type="text/javascript" th:src="@{/rechargeCoinRes/js/ui-choose.js}"></script>
<script src="/js/sweetAlert.js"></script>

<script type="text/javascript">
    // 将所有.ui-choose实例化
    $('.ui-choose').ui_choose();
    // uc_01 ul 单选
    var uc_01 = $('#uc_01').data('ui-choose'); // 取回已实例化的对象
    // uc_01.click = function(index, item) {
        // $('.rechnum').html(item.val());
    // };
    // uc_01.change = function(index, item) {
        // $('.rechnum').html(item.val());
    // };
    $('#uc_01 li input:radio').click(function() {
        console.log($(this).val());
        $('.rechnum').html("¥ " +$(this).val());
    });
    $(function() {
        $('#doc-vld-msg').validator({
            validateOnSubmit: true,
            onValid: function(validity) {
                $(validity.field).closest('.am-form-group').find('.am-alert').hide();
            },
            onInValid: function(validity) {
                var $field = $(validity.field);
                var $group = $field.closest('.am-form-group');
                var $alert = $group.find('.am-alert');
                // 使用自定义的提示信息 或 插件内置的提示信息
                var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
                if(!$alert.length) {
                    $alert = $('<div class="am-alert am-alert-danger"></div>').hide().
                    appendTo($group);
                }
                $alert.html(msg).show();
            },
            submit: function(event) {
                if(this.isFormValid()){
                    event.preventDefault();
                    payOrder();
                }else{
                    return false;
                }
            }
        });
    });
    function payOrder(){
        var money = $('#uc_01 li input:checked').val();  //支付的钱
        if(money == "" || money == null) {
            swal("提示", "请选择套餐！", "warning");
            return false;
        }
        //1. AliPay需要的参数
        var WIDout_trade_no = Date.now();   //根据系统时间获得一个随机数 作为订单号
        var WIDsubject = "购买可观看次数";    //购买的东西
        var WIDtotal_amount = money;
        var WIDbody = "购买可观看次数";
        params = {
            'WIDout_trade_no':WIDout_trade_no,
            'WIDsubject':WIDsubject,
            'WIDtotal_amount':WIDtotal_amount,
            'WIDbody':WIDbody,
            'subPackType':1,
        };
        Post("/subscriptionPackage/payPage",params);
    }

    /**
     *   功能： 模拟form表单的提交
     *   参数： URL 跳转地址 PARAMTERS 参数
    */
    function Post(URL, PARAMTERS) {
        //创建form表单
        var temp_form = document.createElement("form");
        temp_form.action = URL;
        //如需打开新窗口，form的target属性要设置为'_blank'
        // temp_form.target = "_self";
        temp_form.method = "post";
        temp_form.style.display = "none";
        document.body.appendChild(temp_form);
        //添加参数
        for (var item in PARAMTERS) {
            var opt = document.createElement("input");
            opt.type = "text";
            opt.name = item;
            console.log(item);
            opt.value = PARAMTERS[item];
            temp_form.appendChild(opt);
        }
        //提交数据
        temp_form.submit();
        document.body.removeChild(temp_form);
    }

    /**
     * 个人主页
     * @param userId
     */
    function userMainPage(userId) {
        window.location.href = "/user/userMainPage?userId=" + userId;
    }

</script>
</body>

</html>